﻿using System.Reflection;

class Reflection
{ 
    public static void Main(string[] args)
    {
        Type type = typeof(Person);
        Console.WriteLine("所有方法名：");
        foreach (MethodInfo item in type.GetMethods())
        {
            Console.WriteLine(item.Name);
        }
        Console.WriteLine("所有属性名：");
        foreach (PropertyInfo item in type.GetProperties())
        {
            Console.WriteLine(item.Name);
        }

        Type t = typeof(Person);
        object obj = new Person();
        MethodInfo sayhi = t.GetMethod("SayHi");
        object o = sayhi.Invoke(obj, new object[] {"thune"});
    }

    public class Person
    {
        public string? Name { get; set; }
        public int Age { get; set; }
        public string? Sex { get; set; }
        public void SayHi(string name)
        {
            Console.WriteLine("Hi! I am {0} ", name);
        }
    }
}